package com.gxa.dto;

import com.gxa.exception.ErrorType;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 用于传递 add页面 与 edit页面的数据
 * 用于封装所有返回前端的数据，使得layui能够正确解析
 */
@NoArgsConstructor
@AllArgsConstructor
@Data
public class ResponseResult<T> {
    private Integer code;
    private String msg;
    private Integer count;
    private T data;

    public ResponseResult(int code, String mesage) {
        setCode(code);
        setMsg(mesage);
    }

    public ResponseResult(int code, String mesage, Integer count) {
        setCode(code);
        setMsg(mesage);
        setCount(count);
    }

    public ResponseResult(ErrorType errorCode, Integer count) {
        setCodeMessage(errorCode);
        setCount(count);
    }

    public ResponseResult(ErrorType errorCode, Integer count, T data) {
        setCodeMessage(errorCode);
        setCount(count);
        setData(data);
    }

    public ResponseResult setCodeMessage(ErrorType codeMessage) {
        setCode(codeMessage.getCode());
        setMsg(codeMessage.getMsg());
        return this;
    }


}
